<template>
  <div>
    <Drawer
      ref="modal"
      :title="`${editType === 'create' ? $t('devicesCreate.devCreateAdd') : $t('devicesCreate.devCreateEdit')}`"
      :width="600"
      :value="show"
      :beforeClose="$_modal_decideIfClose"
    >
      <Form
        ref="form"
        :labelWidth="150"
        :model="formData"
        :rules="formRule"
      >
        <FormItem prop="sn" :label="$t('devicesCreate.devCreateNumber')">
          <!-- <Input v-model="formData.sn" :placeholder="$t('devicesCreate.devCreateNumberHint')" /> -->
          <div>{{formData.sn}}</div>
        </FormItem>
        <FormItem prop="deviceType" :label="$t('devicesCreate.devCreateType')">
          <Select
            style="width:200px"
            v-model="formData.deviceType"
            :placeholder="$t('devicesCreate.devCreateTypeHint')"
          >
            <Option
              v-for="(item, idx) in deviceType" :key="idx"
              :value="item.value"
              :label="item.name"
            >
            </Option>
          </Select>
        </FormItem>

        <FormItem :label="$t('devicesCreate.devTimezones')">
          <div>{{timezone}}</div>
          <!-- <Select
            disabled
            style="width:200px"
            v-model="timezone"
            :placeholder="$t('devicesCreate.devTimezonessEL')"
          >
            <Option
              v-for="(item, idx) in timezones" :key="idx"
              :value="item.value"
              :label="item.name"
            >
            </Option>
          </Select> -->
        </FormItem>

        <FormItem prop="productId" :label="$t('devicesCreate.devCreateProductType')">
          <Select
            style="width:200px"
            v-model="formData.productId"
            :placeholder="$t('devicesCreate.devCreateProductTypeHint')"
          >
            <Option
              v-for="(item, idx) in productIds" :key="idx"
              :value="item.value"
              :label="item.name"
            >
            </Option>
          </Select>
        </FormItem>
        <FormItem prop="name" :label="$t('devicesCreate.devCreateEquipmentName')">
          <Input v-model.trim="formData.name" :placeholder="$t('devicesCreate.devCreateEquipmentHint')" />
        </FormItem>
        <FormItem :label="$t('devicesCreate.devCreateSetName')">
          <i-switch v-model="ifAdvanced" />
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="isEg" :label="$t('devicesCreate.devCreateIsOpen')">
          <i-switch
            v-model="formData.isEg"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsOpenN") }}</span>
          </i-switch>
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="isTemp" :label="$t('devicesCreate.devCreateIsOpenHeat')">
          <i-switch
            v-model="formData.isTemp"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsOpenN") }}</span>
          </i-switch>
        </FormItem>



        <FormItem v-show="ifAdvanced" prop="isIr" :label="$t('devicesCreate.devCreateIsOpenLive')">
          <i-switch
            v-model="formData.isIr"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsOpenN") }}</span>
          </i-switch>
        </FormItem>

        <FormItem v-show="ifAdvanced" prop="disassemblySwitch" :label="$t('devicesCreate.devCreateDisassembly')">
          <i-switch
            v-model="formData.disassemblySwitch"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsOpenN") }}</span>
          </i-switch>
        </FormItem>

        <FormItem v-show="ifAdvanced" prop="lowPowerSwitch" :label="$t('devicesCreate.devCreateLowPowerSwitch')">
          <i-switch
            v-model="formData.lowPowerSwitch"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsOpenN") }}</span>
          </i-switch>
        </FormItem>

        <FormItem v-show="ifAdvanced" prop="isVi" :label="$t('devicesCreate.devCreateIsOpenVisitors')">
          <i-switch
            v-model="formData.isVi"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsOpenN") }}</span>
          </i-switch>
        </FormItem>

        <FormItem v-show="ifAdvanced" prop="isFahrenheit" :label="$t('devicesCreate.devCreateIsFahrenheit')">
          <i-switch
            v-model="formData.isFahrenheit"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesIndex.devOfflineAccessYes") }}</span>
            <span slot="close">{{ $t("devicesIndex.devOfflineAccessNo") }}</span>
          </i-switch>
        </FormItem>


        <FormItem v-show="ifAdvanced" prop="isUploadStrangerAccess" :label="$t('devicesCreate.devCreateIsDiscern')">
          <i-switch
            v-model="formData.isUploadStrangerAccess"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesIndex.devOfflineAccessYes") }}</span>
            <span slot="close">{{ $t("devicesIndex.devOfflineAccessNo") }}</span>
          </i-switch>
        </FormItem>

        <FormItem v-show="ifAdvanced" prop="isUploadUserWithPhoto" :label="$t('devicesCreate.devCreateIsImg')">
          <i-switch
            v-model="formData.isUploadUserWithPhoto"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesIndex.devOfflineAccessYes") }}</span>
            <span slot="close">{{ $t("devicesIndex.devOfflineAccessNo") }}</span>
          </i-switch>
        </FormItem>

        <FormItem v-show="ifAdvanced" prop="isMaskRecognition" :label="$t('devicesCreate.devCreateIsFacemaskt')">
          <RadioGroup v-model="formData.isMaskRecognition">
              <Radio label="0">
                  <span>{{ $t("devicesCreate.devCreateOpenNo") }}</span>
              </Radio>
              <Radio label="1">
                  <span>{{ $t("devicesCreate.devCreateRemind") }}</span>
              </Radio>
              <Radio label="2">
                  <span>{{ $t("devicesCreate.devCreateControl") }}</span>
              </Radio>
          </RadioGroup>
        </FormItem>

        <FormItem v-show="ifAdvanced" prop="openDoorType" :label="$t('devicesCreate.devCreateOpenDoorType')">
           <RadioGroup v-model="formData.openDoorType">
              <Radio label="1">
                  <span>{{ $t("devicesCreate.devCreateICopen") }}</span>
              </Radio>
              <Radio label="2">
                  <span>{{ $t("devicesCreate.devCreateNormalOpen") }}</span>
              </Radio>
              <Radio label="3">
                  <span>{{ $t("devicesCreate.devCreateNormalOpenIc") }} </span>
              </Radio>
          </RadioGroup>
        </FormItem>

        <!-- <FormItem v-show="ifAdvanced" prop="environment" :label="$t('devicesCreate.devCreateEnvironment')">
           <RadioGroup v-model="formData.environment">
              <Radio label="N">
                  <span>{{ $t("devicesCreate.devCreateEnvironment1") }}</span>
              </Radio>
              <Radio label="BW">
                  <span>{{ $t("devicesCreate.devCreateEnvironment2") }}</span>
              </Radio>
          </RadioGroup>
        </FormItem> -->
        <FormItem v-show="ifAdvanced" prop="recoDistance" :label="$t('devicesCreate.devCreateLight')">
           <RadioGroup v-model="formData.recoDistance">
              <Radio label="1">
                  <span>1</span>
              </Radio>
              <Radio label="2">
                  <span>2</span>
              </Radio>
              <Radio label="3">
                  <span>3</span>
              </Radio>
          </RadioGroup>
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="hardHatRecognition" :label="$t('devicesCreate.hardHatRecognition')">
           <RadioGroup v-model="formData.hardHatRecognition">
              <Radio label="0">
                  <span>{{$t('devicesCreate.hardHatRecognition0')}}</span>
              </Radio>
              <Radio label="1">
                  <span>{{$t('devicesCreate.hardHatRecognition1')}}</span>
              </Radio>
              <Radio label="2">
                  <span>{{$t('devicesCreate.hardHatRecognition2')}}</span>
              </Radio>
          </RadioGroup>
        </FormItem>       
        <FormItem v-show="ifAdvanced" prop="tempComp" :label="$t('devicesCreate.devCreateHeatMake')">
          <InputNumber
            v-model="formData.tempComp"
            :min="-20.99" :max="20.99"
            :step="0.001"
            :style="{ width: '100px' }"
          />
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="tempThreshold" :label="$t('devicesCreate.devCreateThreshold')">
          <InputNumber
            v-model="formData.tempThreshold"
            :min="0" :max="100"
            :step="0.001"
            :style="{ width: '100px' }"
          />
        </FormItem>
        <!-- <FormItem v-show="ifAdvanced" prop="tempAbnormalOpen" :label="$t('devicesCreate.devCreateIsAbnormalOpen')">
          <i-switch
            v-model="formData.tempAbnormalOpen"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsAbnormalOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsAbnormalOpenN") }}</span>
          </i-switch>
        </FormItem> -->
        <FormItem v-show="ifAdvanced" prop="identifyIdCardValue" :label="$t('devicesCreate.devIdentifyIdCardValue')">
          <Slider v-model="formData.identifyIdCardValue"></Slider>
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="volume" :label="$t('devicesCreate.devCreateVolume')">
          <Slider v-model="formData.volume"></Slider>
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="identifyWaitTime" :label="$t('devicesCreate.devCreateAwait')">
          <InputNumber
            v-model="formData.identifyWaitTime"
            :min="0"
            :step="0.1"
            :style="{ width: '100px' }"
          />
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="faceFeaturePairNumber" :label="$t('devicesCreate.devCreateFace')">
          <InputNumber
            v-model="formData.faceFeaturePairNumber"
            :min="0" :max="100"
            :step="0.001"
            :style="{ width: '100px' }"
          />
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="lowPowerTimes" :label="$t('devicesCreate.devLowPowerTimes')">
          <InputNumber
            v-model="formData.lowPowerTimes"
            :min="0" :max="10000000"
            :step="1000"
            :style="{ width: '100px' }"
          />
        </FormItem>
        <!-- <FormItem v-show="ifAdvanced" prop="deviceIntoOrOut" :label="$t('devicesCreate.outType')">
          <i-switch
            v-model="formData.deviceIntoOrOut"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.out") }}</span>
            <span slot="close">{{ $t("devicesCreate.in") }}</span>
          </i-switch>
        </FormItem> -->
        <FormItem v-show="ifAdvanced" prop="isLoose" :label="$t('devicesCreate.isWidth')">
          <i-switch
            v-model="formData.isLoose"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesIndex.devOfflineAccessYes") }}</span>
            <span slot="close">{{ $t("devicesIndex.devOfflineAccessNo") }}</span>
          </i-switch>
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="usernameMasking" :label="$t('devicesCreate.usernameMasking')">
          <i-switch
            v-model="formData.usernameMasking"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsOpenN") }}</span>
          </i-switch>
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="isCardShow" :label="$t('devicesCreate.isCardShow')">
          <i-switch
            v-model="formData.icCardShow"
            :true-value="1"
            :false-value="0"
            size="large"
          >
            <span slot="open">{{ $t("devicesCreate.devCreateIsOpenY") }}</span>
            <span slot="close">{{ $t("devicesCreate.devCreateIsOpenN") }}</span>
          </i-switch>
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="ntpServerUrl" :label="$t('devicesCreate.ntpUrl')">
           <Input v-model="formData.ntpServerUrl" :placeholder="$t('companyManagement.pleaseEnter')" />
        </FormItem> 
        <FormItem v-show="ifAdvanced" prop="officeTime" :label="$t('devicesCreate.devInfraredOnTime')">
           <Tag v-for="(item,index) in countTime" :key="index" :name = "item.time" closable @on-close="handleClose2">{{ item.time }}</Tag>
           <Button icon="ios-add" type="dashed" size="small" @click="handleAdd">{{ $t("devicesCreate.devCreateAddTime") }}</Button>
           <br><TimePicker v-if="countTimeSel" confirm
           format="HH:mm"
           v-model="officeTime"
           type="timerange"
           @on-ok = 'timeOk'
           @on-open-change = 'maskIsOpen'
           placement="bottom-end" :placeholder="$t('devicesCreate.devCreateSelTime')" style="width: 168px"></TimePicker>
        </FormItem>
        <FormItem v-show="ifAdvanced" prop="bluetoothMac" :label="$t('devicesCreate.bluetoothMac')">
           <Input v-model="formData.bluetoothMac" maxlength="200"  :placeholder="$t('companyManagement.pleaseEnter')" />
        </FormItem> 
        <FormItem class="glo-btn-group">
          <Button
            type="primary"
            :loading="loading"
            @click="handleSubmit"
          >{{ $t("devicesCreate.devCreateSubmit") }}</Button>
          <Button
            @click="$_modal_close"
          >{{ $t("devicesCreate.devCreateCancel") }}</Button>
        </FormItem>
      </Form>
    </Drawer>
  </div>
</template>

<script>
import _ from 'lodash'
import {
  mapState,
} from 'vuex'

import modalMixin from '@/utils/mixins/modalMixin.js'
import {
  create,
  update,
} from '@/api/device.js'

const DEFAULT_FORM = {
  sn: '',
  deviceType: 'F800W',
  // timezone: '',
  productId: '',
  name: '',
  isEg: 1,
  isTemp: 1,
  isIr: 1,
  disassemblySwitch: 1,
  lowPowerSwitch: 1,
  isVi: 0,
  isFahrenheit: 0,
  isMaskRecognition: '1',
  openDoorType: '3',
  protocolVersion:'',
  isUploadStrangerAccess: 0,
  isUploadUserWithPhoto: 1,
  environment: 'N',
  recoDistance: 2,
  hardHatRecognition: '1',
  tempComp: 0,
  tempThreshold: 37.3,
  tempAbnormalOpen: 0,
  identifyWaitTime: 0,
  faceFeaturePairNumber: 73.28,
  lowPowerTimes: 3000,
  volume: 25,
  identifyIdCardValue: 60,
  deviceIntoOrOut:0,//设备进出的类型0：进，1：出
  isLoose:1,//宽动态模式 1是 0否
  usernameMasking:0,//人员姓名显示是否脱敏 1是 0否
  icCardShow:0,//ic卡号显示开关 1显示 0不显示
  ntpServerUrl:'',//ntp服务器url
  bluetoothMac:'',//蓝牙mac地址
}

export default {
  mixins: [
    modalMixin,
  ],

  props: {
    editType: {
      type: String,
      default: 'create',
    },
    editItem: Object,
  },
  data () {
    return {
      countTime: [],
      countTimeSel: false,
      officeTime: '',
      deviceType: [
        { name: 'F800W', value: 'F800W' },
      ],
      timezone: '',
      timezones: [
        { name: this.$t('devicesCreate.devTimezone1'), value: '(UTC+08:00)' },
        { name: this.$t('devicesCreate.devTimezone5'), value: '(UTC+09:00)' },
        { name: this.$t('devicesCreate.devTimezone7'), value: '(UTC+04:00)' },
        { name: this.$t('devicesCreate.devTimezone8'), value: '(UTC+02:00)' },
        { name: this.$t('devicesCreate.devTimezone9'), value: '(UTC+03:00)' },
        { name: this.$t('devicesCreate.devTimezone12'), value: '(UTC+07:00)' },
        { name: this.$t('devicesCreate.devTimezone14'), value: '(UTC+05:30)' },
        { name: this.$t('devicesCreate.devTimezone18'), value: '(UTC+06:00)' },
        { name: this.$t('devicesCreate.devTimezone20'), value: '(UTC+05:00)' },
        { name: this.$t('devicesCreate.devTimezone22'), value: '(UTC-10:00)' },
        { name: this.$t('devicesCreate.devTimezone23'), value: '(UTC+05:45)' },
        { name: this.$t('devicesCreate.devTimezone25'), value: '(UTC+03:30)' },
        { name: this.$t('devicesCreate.devTimezone27'), value: '(UTC+08:30)' },
        { name: this.$t('devicesCreate.devTimezone28'), value: '(UTC+06:30)' },
        { name: this.$t('devicesCreate.devTimezone29'), value: '(UTC-05:00)' },
        { name: this.$t('devicesCreate.devTimezone33'), value: '(UTC+10:00)' },
        { name: this.$t('devicesCreate.devTimezone34'), value: '(UTC+01:00)' },
        { name: this.$t('devicesCreate.devTimezone38'), value: '(UTC+00:00)' },
        { name: this.$t('devicesCreate.devTimezone41'), value: '(UTC-06:00)' },
        { name: this.$t('devicesCreate.devTimezone47'), value: '(UTC-07:00)' },
        { name: this.$t('devicesCreate.devTimezone48'), value: '(UTC-02:00)' },
        { name: this.$t('devicesCreate.devTimezone50'), value: '(UTC+09:30)' },
        { name: this.$t('devicesCreate.devTimezone51'), value: '(UTC+08:45)' },
        { name: this.$t('devicesCreate.devTimezone52'), value: '(UTC-03:00)' },
      ],
      productIds: [
        { name: this.$t('devicesCreate.devCreateMachine'), value: 1 },
        { name: this.$t('devicesCreate.devCreateGuard'), value: 2 },
      ],
      ifAdvanced: true,
      formData: _.cloneDeep(DEFAULT_FORM),
      formRule: {
        // sn: { required: true, message: this.$t('devicesCreate.devCreatemustN') },
        name: { required: true, message: this.$t('devicesCreate.devCreatemustR') },
        productId: { required: true, message: this.$t('devicesCreate.devCreatemustT') },
      },
    }
  },
  computed: {
    ...mapState([
      'departId',
    ]),
  },

  mounted () {
    this.show = true
    if (this.editType === 'update') {
      const formData = {}
      if(this.editItem.openDoorType=='null'){
        this.editItem.openDoorType='1'
      }
      const keys = Object.keys(DEFAULT_FORM)
      keys.forEach(key => {
        formData[key] = _.isUndefined(this.editItem[key])
          ? DEFAULT_FORM[key]
          : this.editItem[key]
      })
      formData.deviceId = this.editItem.deviceId
      console.log(formData)
      console.log(this.editItem)
      if (this.editItem.infraredOnTime) {
        let aArr  = this.editItem.infraredOnTime.split('、')
        console.log(aArr)
        aArr.forEach((item, index) => {
          this.countTime.push({time: item})
        })
        console.log(this.countTime)
      }
      if (this.editItem.timezone) {
        let dataValue = this.timezones.find(item => item.value == this.editItem.timezone)
        this.timezone = dataValue.name
      }else{
        this.timezone = this.$t('devicesCreate.devCreatemustNo')
      }
      
      this.formData = _.cloneDeep(formData)
      this.formData.openDoorType=this.formData.openDoorType+''
      this.formData.isMaskRecognition = this.formData.isMaskRecognition+''
      this.formData.hardHatRecognition = this.formData.hardHatRecognition+''
    }
  },

  methods: {

    handleAdd () {
      if(this.countTimeSel){
        this.countTimeSel = false
        return
      }
      this.countTimeSel = true
    },
    handleClose2 (event, name) {
      this.countTime.splice(this.countTime.findIndex(item => item.time === name), 1)
    },
    timeOk () {
      if (this.officeTime[0]) {
        let aTime = `${this.officeTime[0]}-${this.officeTime[1]}`
        var aTrue = JSON.stringify(this.countTime)
        if (aTrue.includes(aTime)) {
          this.$Message.error(
            {
              content: this.$t('devicesCreate.devExistingTime'),
              duration: 3,
            }
          )
          return
        }
        this.officeTime = ''
        this.countTime.push({ time: aTime })
      }
    },
    maskIsOpen (event) {
      console.log(event)
      if (!event) this.countTimeSel = false
      // console.log(this.officeTime)
    },
    async handleSubmit () {
      const ifVlid = await this.$refs.form.validate()
      if (ifVlid && this.editType === 'create') {
        this.handleCreate()
      }
      if (ifVlid && this.editType === 'update') {
        this.handleUpdate()
      }
    },

    async handleCreate () {
      if (!this.formData.environment) {
        this.formData.environment = 0
      }
      
      if (this.formData.isFahrenheit == null) {
        this.formData.isFahrenheit = 0
      }
      if (this.formData.isEg == 0 && this.formData.isTemp == 0) {
        this.$Message.error(this.$t('devicesCreate.devCreateIsOpenOne'))
        return
      }
      const formData = _.cloneDeep(this.formData)
      formData.departId = this.departId
      const { success } = await create(formData)
      if (success) {
        this.$Message.success(this.$t('devicesCreate.devCreateS'))
        this.ifUpdateUpper = true
        this.$_modal_close()
      } else {
        this.$Message.error(this.$t('devicesCreate.devCreateN'))
      }
    },
    async handleUpdate () {
      if (!this.formData.environment) {
        this.formData.environment = 'N'
      }
      if (!this.formData.hardHatRecognition) {
        this.formData.hardHatRecognition = 0
      }else{
        this.formData.hardHatRecognition=Number(this.formData.hardHatRecognition)
      }
      if (!this.formData.isMaskRecognition) {
        this.formData.hardHatRecognition = 0
      }else{
        this.formData.isMaskRecognition=Number(this.formData.isMaskRecognition)
      }
      // console.log(this.formData.isFahrenheit)
      console.log(this.formData.isFahrenheit == null)
      if (this.formData.isFahrenheit == null) {
        this.formData.isFahrenheit = 0
      }
      if (this.formData.isEg == null) {
        this.formData.isEg = 1
      }
      if (this.formData.isIr == null) {
        this.formData.isIr = 1
      }
      if (this.formData.isTemp == null) {
        this.formData.isTemp = 1
      }
      if (this.formData.tempComp == null) {
        this.formData.tempComp = 0
      }
      if (this.formData.tempThreshold == null) {
        this.formData.tempThreshold = 37.3
      }
      if (this.formData.tempAbnormalOpen == null) {
        this.formData.tempAbnormalOpen = 0
      }
      if (this.formData.identifyWaitTime == null) {
        this.formData.identifyWaitTime = 0
      }
      if (this.formData.faceFeaturePairNumber == null) {
        this.formData.faceFeaturePairNumber = 73.28
      }
      if (this.formData.volume == null) {
        this.formData.volume = 25
      }
      if (this.formData.openDoorType == null||!this.formData.openDoorType) {
        this.formData.openDoorType = 1
      }else{
        this.formData.openDoorType=Number(this.formData.openDoorType)
      }
      if (this.countTime.length > 0) {
        let aTime = ''
        this.countTime.forEach((item, index) => {
          aTime += item.time + '、'
        })
        this.formData.infraredOnTime = aTime.substr(0, aTime.length - 1)

      } else {
        this.formData.infraredOnTime = ''
      }
      console.log(this.countTime)
      // if (this.formData.timezone == null) {
      //   this.formData.timezone = '(UTC+08:00)'
      // }
      if (this.formData.isEg == 0 && this.formData.isTemp == 0) {
        this.$Message.error(this.$t('devicesCreate.devCreateIsOpenOne'))
        return
      }
      const formData = _.cloneDeep(this.formData)
      // formData.departId = this.departId
      const { success } = await update(formData)
      if (success) {
        this.$Message.success(this.$t('devicesCreate.devCreateUpdateS'))
        this.ifUpdateUpper = true
        this.$_modal_close()
      } else {
        this.$Message.error(this.$t('devicesCreate.devCreateUpdateN'))
      }
    },
  },
}
</script>
